import { _decorator, Component, Node, Button } from 'cc';
import { GameManager } from './GameManager';
const { ccclass, property } = _decorator;

@ccclass('HomePanelController')
export class HomePanelController extends Component {
    @property(Button)
    startGameBtn: Button = null!;

    @property(Button)
    continueGameBtn: Button = null!;

    @property(Button)
    selectLevelBtn: Button = null!;

    @property(Button)
    settingsBtn: Button = null!;

    start() {
        // 开始游戏按钮
        this.startGameBtn.node.on(Button.EventType.CLICK, this.onStartGame, this);
        
        // 继续游戏按钮
        this.continueGameBtn.node.on(Button.EventType.CLICK, this.onContinueGame, this);
        
        // 选择关卡按钮
        this.selectLevelBtn.node.on(Button.EventType.CLICK, this.onSelectLevel, this);
        
        // 设置按钮
        this.settingsBtn.node.on(Button.EventType.CLICK, this.onSettings, this);
    }

    onStartGame() {
        GameManager.instance.startNewGame();
    }

    onContinueGame() {
        GameManager.instance.continueGame();
    }

    onSelectLevel() {
        GameManager.instance.showLevelSelection();
    }

    onSettings() {
        GameManager.instance.showSettings();
    }

    onDestroy() {
        // 清理事件监听
        if (this.startGameBtn && this.startGameBtn.node) {
            this.startGameBtn.node.off(Button.EventType.CLICK, this.onStartGame, this);
        }
        if (this.continueGameBtn && this.continueGameBtn.node) {
            this.continueGameBtn.node.off(Button.EventType.CLICK, this.onContinueGame, this);
        }
        if (this.selectLevelBtn && this.selectLevelBtn.node) {
            this.selectLevelBtn.node.off(Button.EventType.CLICK, this.onSelectLevel, this);
        }
        if (this.settingsBtn && this.settingsBtn.node) {
            this.settingsBtn.node.off(Button.EventType.CLICK, this.onSettings, this);
        }
    }

    update(deltaTime: number) {
        
    }
}


